home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Announcer / Ear.h < prev    next >
Encoding:
Text File  |  1997-06-28  |  966 b   |  55 lines  |  [TEXT/CWIE]

  1. // Ear.h
  2.  
  3. #ifndef Ear_h
  4. #define Ear_h
  5.  
  6. #ifndef EarBase_h
  7. #include "EarBase.h"
  8. #endif
  9.  
  10. template < class Head >
  11. class Ear: public EarBase
  12.   {
  13.     typedef Head HeadType;
  14.     typedef void (HeadType::*Nerve)();
  15.     
  16.     private:
  17.         Head& head;
  18.         const Nerve announcement;
  19.         const Nerve destruction;
  20.     
  21.     public:
  22.         Ear( Head& theHead, Nerve announce, Nerve destroy = 0 )
  23.           : EarBase(),
  24.              head( theHead ),
  25.              announcement( announce ),
  26.              destruction( destroy )
  27.           {
  28.             Assert( announcement != 0 );
  29.           }
  30.         
  31.         Ear( const Announcer& announcer, Head& theHead, Nerve announce, Nerve destroy = 0 )
  32.           : EarBase( announcer ),
  33.              head( theHead ),
  34.              announcement( announce ),
  35.              destruction( destroy )
  36.           {
  37.             Assert( announcement != 0 );
  38.           }
  39.         
  40.         virtual void HearAnnouncement()
  41.           {
  42.             head.SetContext();
  43.             (head.*announcement)();
  44.           }
  45.         
  46.         virtual void HearDestruction()
  47.           {
  48.             head.SetContext();
  49.             Assert( destruction != 0 );
  50.             (head.*destruction)();
  51.           }
  52.   };
  53.  
  54. #endif
  55.